package com.ejiaoyi.api.config;

import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Component;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * Knife4j 配置
 *
 * @author unknownChivalrous
 * @since 2020-03-17
 */
@Component
@Configuration
@EnableKnife4j
@EnableSwagger2
@ConditionalOnProperty(value = {"knife4j.enable"}, matchIfMissing = true)
public class Knife4jConfig {

    @Bean
    public Docket apiV1() {

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("V1")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.ejiaoyi.api.controller.v1"))
                .paths(PathSelectors.any())
                .build();
    }

    /*
    多个Docket 实现版本控制
    public Docket apiV2() {

        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .groupName("V2")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.ejiaoyi.api.controller.v2"))
                .paths(PathSelectors.any())
                .build();
    }*/

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder().title("企业运行平台接口")
                .description("企业运行平台接口")
                .version("1.0")
                .contact(new Contact("fengjunhong", "", ""))
                .build();
    }
}
